<template>
  <div class="app-container">
    <el-tabs v-model="activeName" @tab-click="handleClick" type="border-card">
      <el-tab-pane label="入库记录" name="first">
        <el-table
          v-loading="loading"
          :data="list1"
          :stripe="true"
          :show-overflow-tooltip="true"
          @selection-change="handleRowCheckboxChange"
        >
          <el-table-column type="selection" width="55"/>
          <el-table-column label="任务单号" align="center" prop="workOrderNo" />
          <el-table-column label="业务类型" align="center" prop="procedureWorkOrderNo" />
          <el-table-column label="入库库位" align="center" prop="planNo" />
          <el-table-column label="创建时间" align="center" prop="createTime" width="180">
            <template v-slot="scope">
              <span>{{ parseTime(scope.row.createTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="单据状态" align="center" prop="planNo" />
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="出库记录" name="second">
        <el-table
          v-loading="loading"
          :data="list2"
          :stripe="true"
          :show-overflow-tooltip="true"
          @selection-change="handleRowCheckboxChange"
        >
          <el-table-column type="selection" width="55"/>
          <el-table-column label="任务单号" align="center" prop="workOrderNo" />
          <el-table-column label="业务类型" align="center" prop="procedureWorkOrderNo" />
          <el-table-column label="出库库位" align="center" prop="planNo" />
          <el-table-column label="创建时间" align="center" prop="createTime" width="180">
            <template v-slot="scope">
              <span>{{ parseTime(scope.row.createTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="单据状态" align="center" prop="planNo" />
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="库存明细" name="third">
        <el-table
          v-loading="loading"
          :data="list3"
          :stripe="true"
          :show-overflow-tooltip="true"
          @selection-change="handleRowCheckboxChange"
        >
          <el-table-column type="selection" width="55"/>
          <el-table-column label="批次号" align="center" prop="workOrderNo" />
          <el-table-column label="物料名称" align="center" prop="procedureWorkOrderNo" />
          <el-table-column label="物料编码" align="center" prop="planNo" />
          <el-table-column label="数量" align="center" prop="planNo" />
          <el-table-column label="单位" align="center" prop="planNo" />
          <el-table-column label="物料状态" align="center" prop="planNo" />
          <el-table-column label="加工属性" align="center" prop="planNo" />
          <el-table-column label="批次" align="center" prop="planNo" />
          <el-table-column label="库位名称" align="center" prop="planNo" />
          <el-table-column label="追溯码" align="center" prop="planNo" />
          <el-table-column label="创建时间" align="center" prop="createTime" width="180">
            <template v-slot="scope">
              <span>{{ parseTime(scope.row.createTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="单据状态" align="center" prop="planNo" />
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="质检记录" name="fourth">
        <el-table
          v-loading="loading"
          :data="list4"
          :stripe="true"
          :show-overflow-tooltip="true"
          @selection-change="handleRowCheckboxChange"
        >
          <el-table-column type="selection" width="55"/>
          <el-table-column label="单号" align="center" prop="workOrderNo" />
          <el-table-column label="来源单号" align="center" prop="procedureWorkOrderNo" />
          <el-table-column label="质检类型" align="center" prop="planNo" />
          <el-table-column label="合格率" align="center" prop="planNo" />
          <el-table-column label="质检数量" align="center" prop="planNo" />
          <el-table-column label="合格数" align="center" prop="planNo" />
          <el-table-column label="不合格数" align="center" prop="planNo" />
          <el-table-column label="创建时间" align="center" prop="createTime" width="180">
            <template v-slot="scope">
              <span>{{ parseTime(scope.row.createTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="单据状态" align="center" prop="planNo" />
        </el-table>
      </el-tab-pane>
    </el-tabs>


  </div>
</template>

<script>
import * as WorkOrderApi from '@/api/production/workorder';
import * as MaterialApi from '@/api/storage/material';
import {listDept} from "@/api/system/dept";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import Treeselect from "@riophae/vue-treeselect";

export default {
  name: "First",
  components: {
    Treeselect
  },
  data() {
    return {
      activeName: 'first',
      batchNoList: [],
      deptList: [],
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 工单列表
      list1: [],
      list2: [],
      list3: [],
      list4: [],
      // 是否展开，默认全部展开
      isExpandAll: true,
      // 重新渲染表格状态
      refreshTable: true,
      // 选中行
      currentRow: {},
      checkedIds: [],
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        workOrderNo: null,
        procedureWorkOrderId: null,
        procedureWorkOrderNo: null,
        planId: null,
        planNo: null,
        deptId: null,
        deptName: null,
        productId: null,
        productName: null,
        productCode: null,
        materialId: null,
        materialNo: null,
        materialName: null,
        procedureId: null,
        procedureCode: null,
        procedureName: null,
        deviceId: null,
        deviceCode: null,
        deviceName: null,
        planBeginTime: [],
        planEndTime: [],
        actualBeginTime: [],
        actualEndTime: [],
        daySendWorkNumber: null,
        status: null,
        createTime: [],
      },
    };
  },
  created() {
    this.getList();
    this.getDeptList();
  },
  methods: {
    handleClick(e) {
      console.log(e._props.label, 'czq')
    },
    async getDeptList() {
      const res = await MaterialApi.getMaterialPage({pageNo: 1, pageSize: 50});
      this.batchNoList = res.data.list;
    },

    /** 部门节点格式化 */
    normalizer(node) {
      return {
        id: node.id,
        label: node.name,
        children: node.children,
      };
    },
    toDetail(id) {
      this.$router.push({
        path: '/production/detail',
        query: {id: id}
      });
    },
    /** 查询列表 */
    async getList() {
      try {
        this.loading = true;
        const res = await WorkOrderApi.getWorkOrderPage(this.queryParams);
        this.list = res.data.list;
        this.total = res.data.total;
      } finally {
        this.loading = false;
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 添加/修改操作 */
    openForm(id) {
      this.$refs["formRef"].open(id);
    },
    /** 删除按钮操作 */
    async handleDelete(row) {
      const id = row.id;
      await this.$modal.confirm('是否确认删除工单编号为"' + id + '"的数据项?')
      try {
        await WorkOrderApi.deleteWorkOrder(id);
        await this.getList();
        this.$modal.msgSuccess("删除成功");
      } catch {
      }
    },
    /** 批量删除工单 */
    async handleDeleteBatch() {
      await this.$modal.confirm('是否确认删除?')
      try {
        await WorkOrderApi.deleteWorkOrderList(this.checkedIds);
        this.checkedIds = [];
        await this.getList();
        this.$modal.msgSuccess("删除成功");
      } catch {
      }
    },
    handleRowCheckboxChange(records) {
      this.checkedIds = records.map((item) => item.id);
    },
    /** 导出按钮操作 */
    async handleExport() {
      await this.$modal.confirm('是否确认导出所有工单数据项?');
      try {
        this.exportLoading = true;
        const data = await WorkOrderApi.exportWorkOrderExcel(this.queryParams);
        this.$download.excel(data, '工单.xls');
      } catch {
      } finally {
        this.exportLoading = false;
      }
    },
  }
};
</script>
